// crc32.h
#ifndef CRC32_SIMPLE_H
#define CRC32_SIMPLE_H

#include <QByteArray>

class CRC32
{
public:
    static quint32 calculate(const QByteArray &data)
    {
        quint32 crc = 0xFFFFFFFF;
        const quint32 polynomial = 0xEDB88320;

        for (char ch : data) {
            quint8 byte = static_cast<quint8>(ch);
            crc ^= byte;
            for (int i = 0; i < 8; ++i) {
                if (crc & 1)
                    crc = (crc >> 1) ^ polynomial;
                else
                    crc >>= 1;
            }
        }

        return crc ^ 0xFFFFFFFF;
    }
};

#endif // CRC32_SIMPLE_H
